<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" slot="detail" :rules="validatorRules" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="指派部门" prop="orgDeptCode">
          <j-select-depart v-model="model.orgDeptCode" customReturnField="orgCode" backRows @backRows="getBack" />
        </a-form-model-item>
        <a-form-model-item v-if="showFlowSubmitButton">
          <a-button @click="submitForm">提 交</a-button>
        </a-form-model-item>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
  import { batchAppoint } from '@/api/warning/WarningData.js'
  export default {
    name: "AssignForm",
    data () {
      return {
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          orgDeptCode:[ { required: true, message: '请选择部门!' },]
        },
        getSelectKeyDatas: {}
      }
    },
    computed: {
      formDisabled(){
        if(this.normal===false){
          if(this.formData.disabled===false){
            return false
          }else{
            return true
          }
        }
        return this.disabled
      },
      disabledId(){
        return this.id?true : false;
      },
      showFlowSubmitButton(){
        if(this.normal===false){
          if(this.formData.disabled===false){
            return true
          }else{
            return false
          }
        }else{
          return false
        }
      }
    },
    methods: {
      show (record) {
        this.model = record?Object.assign({}, record):this.model;
        this.visible = true;
      },
      getBack(record) {
        let title = record.map(v=>v.title)
        let atitle = title && title.length>0? title.join(','):''
        let value = record.map(v=>v.value)
        let avalue = value && value.length>0? value.join(','):''
        this.$set( this.model, 'orgDeptCname', atitle )
        this.$set( this.model, 'orgDeptId', avalue )
      },
      submitForm () {
        const parameter = Object.assign({}, this.getSelectKeyDatas, this.model)
        batchAppoint(parameter)
          .then((res) => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok');
            } else {
              this.$message.warn(res.message)
            }
          })
          .catch((e) => {
            this.$message.warn('请求失败！')
          })
      }
    }
  }
</script>
